<template>
	<view>
		<view class="bgf">
			<view class="mx-15 borderB disFlxJS linh-50">
				<view class="shrink0 pr-50">
					<view>会议号</view>
				</view>
				<view class="disFlxAC">
					<u--input
						v-model="meetingNum"
						placeholder="请输入会议号"
						border="none"
						inputAlign="right"
						:maxLength="10"
					></u--input>
				</view>
			</view>
			<view class="mx-15">
				<u-button
					type="primary"
					text="加入会议"
					:customStyle="{
						fontSize: '32rpx',
						borderRadius: '20rpx',
						height: '88rpx',
					}"
					:disabled="!meetingNum"
					:throttleTime="500"
					@click="configJoin"
				></u-button>
			</view>
		</view>
	</view>
</template>

<script>
import orderApi from "@/api/order.js";

export default {
	data() {
		return {
			meetingNum: "",
		};
	},
	onLoad() {
		this.$store.dispatch("getUserInfo").then(() => {
			this.$store.dispatch("loginXy"); // 登录小鱼
		});
	},
	methods: {
		async configJoin() {
			try {
				// 获取房间以及会议信息
				const { data } = await orderApi.getRoomInfo({ invitation: this.meetingNum });
				// 调用接口加入IM群组,和创建订单
				await orderApi.userAddRoom({ groupId: data.groupid, orderNo: data.orderNo });

				this.$store.commit("SET_CELLINFO", {
					orderNo: data.orderNo,
					meetingRoomNumber: data.meetingRoomNumber,
					password: data.invitation,
					id: data.sponsorid,
					userName: data.sponsor,
					headimg: "",
				}); // 呼叫信息

				// 消息体,会话页面所需信息
				this.$store.commit("SET_CURRENTMESSAGE", {
					data: {
						hostId: data.sponsorid,
						imGroupId: data.groupid,
            meetingNum: data.meetingRoomNumber,
            meetingPwd: data.invitation
					},
				});
				uni.redirectTo({ url: `/pagesB/meeting/index` });
			} catch (error) {
        uni.showToast({
          title: '查无此房间,请检查邀请码',
          icon: 'none'
        })
      }
		},
	},
};
</script>

<style lang="scss" scoped></style>
